package com.ultrasoft.farmasoft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ultrasoft.farmasoft.domain.Bill;
import com.ultrasoft.farmasoft.domain.Dosage;
import com.ultrasoft.farmasoft.repository.BillDao;
import com.ultrasoft.farmasoft.repository.DosageDao;

@Service
public class OperationNationalTaxationServiceImpl implements OperationNationalTaxationService {

	private DosageDao dosageDao;
	private BillDao billDao;
	
	@Autowired
	public OperationNationalTaxationServiceImpl(BillDao billDao,DosageDao dosageDao){
		this.dosageDao 	= dosageDao;
		this.billDao 	= billDao;
	}
	
	@Transactional(readOnly = true)
	public List<Dosage> getListDosage() {
		return dosageDao.getListDosage();
	}
	@Transactional(readOnly = true)
	public List<Dosage> getListDosageByPharmacyIdOrderBy(Integer pharmacyId) {
		/*
		for (int i = 0; i < 3; i++) {
			System.out.println(" los shorts ");
			List<Dosage> listDosage = dosageDao.getListDosageByPharmacyIdByStateByCurrentDate(pharmacyId,(short)i);
			for (Dosage dosage : listDosage) {
				System.out.println(listDosage);
			}
		}
		*/
		return dosageDao.getListDosageByPharmacyIdOrderBy(pharmacyId);
	}
	@Transactional(readOnly = true)
	public List<Dosage> getListDosageByPharmacyIdByStateOrderBy(Integer pharmacyId,short state) {
		return dosageDao.getListDosageByPharmacyIdByStateOrderBy(pharmacyId, state);
	}
	@Transactional(readOnly = true)
	public Dosage searchDosageByDosageId(Integer dosageId) {
		return dosageDao.findDosageByDosageId(dosageId);
	}
	@Transactional
	public void removeDosage(Dosage dosage) {
		if(dosageDao.verificarDosificacion(dosage.getPharmacyId().getPharmacyId()))
			System.out.println("entro al iffffffffff");
		else
			System.out.println("entro al else ");
		
		dosageDao.remove(dosage);
	}
	@Transactional
	public void updateDosage(Dosage dosage) {
		dosageDao.update(dosage);
	}
	@Transactional
	public void addDosage(Dosage dosage) {
		dosageDao.add(dosage);
	}
	
	
	
	@Transactional(readOnly = true)
	public Integer searchBillIdIdMax(){
		return billDao.findBillIdIdMax();
	}
	@Transactional
	public void addBill(Bill bill){
		billDao.add(bill);
	}

}
